{include file="public/header" /}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.css"}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.js"}
<style>
    #des, #des input {
        width: 40px;
        text-align: center;
    }

    #id {
        width: 78px;
    }

    .bs-checkbox {
        width: 36px;
        height: 40px
    }

    .fixed-table-toolbar .columns, .fixed-table-toolbar .search {
        margin-left: 0;
        margin-top: 0
    }

    #title span {
        float: right;
    }

    .asdlkjasd {
        background: #1ab394;
        color: #fff
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content {:config('adminClass.main')}">
    <div class="ibox float-e-margins">
        {include file="public/tophead"}
        {include file="public/top" /}
        <div class="ibox-content">

            {include file="public/topsection"}

            <div class="row row-lg">
                <div class="col-sm-12">
                    <div class="fixed-table-toolbar" style="text-align: center;margin-bottom: 20px">
                        <h2>人数: <font color="#1ab394">{$count}</font></h2>
                    </div>
                    <div style="display:block;clear: both;"></div>
                    <div class="fixed-table-toolbar">
                        <form method="get" action="" style="display: flex;">
                            <div class="pull-left search" style="display: flex;">
                                <div class="columns columns-right btn-group pull-left">
                                    <select class="form-control" name="search">
                                        <option value="id" {php}if(input(
                                        '?param.search')){if(input('param.search')=='id'){echo "selected";}
                                        }{/php}>ID</option>
                                        <option value="name" {php}if(input(
                                        '?param.search')){if(input('param.search')=='name'){echo "selected";}
                                        }{/php}>昵称</option>
                                        <option value="phone" {php}if(input(
                                        '?param.search')){if(input('param.search')=='phone'){echo "selected";}
                                        }{/php}>手机</option>
                                       <!-- <option value="city" {php}if(input(
                                        '?param.search')){if(input('param.search')=='city'){echo "selected";}
                                        }{/php}>城市</option>-->
                                        <option value="yqm" {php}if(input(
                                        '?param.search')){if(input('param.search')=='yqm'){echo "selected";}
                                        }{/php}>邀请码</option>
                                        <option value="device_id" {php}if(input(
                                        '?param.search')){if(input('param.search')=='device_id'){echo "selected";}
                                        }{/php}>设备号</option>
                                        <option value="ip" {php}if(input(
                                        '?param.search')){if(input('param.search')=='ip'){echo "selected";}
                                        }{/php}>IP</option>
                                    </select>
                                </div>

                                <div class="pull-right search">
                                    <input class="form-control input-outline" type="text"
                                           {php}
                                           if(input('?param.name')){
                                    if(input('param.name')){
                                    echo "value='".input('name')."'";
                                    }

                                    }
                                    {/php}
                                    name="name" placeholder="搜索">
                                </div>

                                <div class="pull-right search">
                                    <button style="border-radius:0px; border:1px solid #e5e6e7; border-left:0px"
                                            class="btn btn-default btn-outline" type="submit">搜索
                                    </button>
                                </div>

                                <input name="date" type="text" id="date" class="form-control layui-input" value="{present name="date"}{$date}{/present}" placeholder="请选择时间" autocomplete="off" style="height:34px;width:100px;margin:0 10px;">

                                {php}
                                if(input('?param.name')){
                                {/php}
                                <div class="pull-right search">
                                    <a class="btn btn-w-m btn-link" href="{:url('indexofip')}">返回列表</a>
                                </div>
                                {php}
                                }
                                {/php}
                            </div>
                        </form>
                    </div>
                    <div class="example">
                        <form class="form-horizontal" method="post">
                            <table data-toggle="table">
                                <thead>
                                <tr>
                                    <th class="bs-checkbox"><input type="checkbox" id="delidAll"></th>
                                    <th data-align="center" data-width="6%">邀请人</th>
                                    {if condition='$uniaccount'}
                                    <th data-align="center">关联描述</th>
                                    {/if}
                                    <th data-align="center">ID</th>
                                    <th data-align="center">头像</th>
                                    <th data-align="center">昵称</th>
                                    <th data-align="center">性别</th>
                                    <th data-align="center">账号数量</th>
                                    <!--<th data-align="center">城市</th>-->
                                    <th data-align="center">手机</th>
                                    <th data-align="center">金币</th>
                                    <th data-align="center">积分</th>
                                    <th data-align="center">总充值</th>
                                    <th data-align="center">总消费</th>
                                    <th data-align="center">总收益</th>
                                    {present name='reward'}
                                        {eq name='$reward' value='1'}
                                            <th data-align="center">收益</th>
                                            <th data-align="center">虚拟收益</th>
                                        {/eq}
                                    {/present}
                                    <th data-align="center">总提现</th>
                                    <th data-align="center">邀请码</th>
                                    <th data-align="center">团队</th>
                                    <th data-align="center">VIP</th>
                                    <!--<th data-align="center">推荐</th>-->
                                    <th data-align="center">认证</th>
                                    <th data-align="center">注册时间</th>
                                    <!--<th data-align="center">排序</th>
                                    <th data-align="center">联系客户</th>
                                    <th data-align="center">状态</th>-->
                                    <th data-align="center">管理</th>
                                </tr>
                                </thead>
                                <tbody id="form">
                                {php}$hide=array('0'=>'<font color="#1ab394">正常</font>','1'=>'<font
                                        color="#f00">冻结</font>');{/php}
                                {volist name="data" id="v"}
                                <tr id="id{$v.id}" class="class">
                                    <td id="delid" ><input name="delAll[]" type="checkbox" value="{$v.id}"></td>
                                    <!--<td><a onclick="member('{$v.yqr}')" style="color:#40BCF7">{:yqmuser($v.yqr)}</a></td>-->
                                    <td><input class="form-control invite" type="text" onblur="input('{$v.id}')" value="{:yqmuser($v.yqr)}" placeholder="{$v.yqr}"></td>
                                    {if condition='$uniaccount'}
                                    <td>{$v.uniobject}</td>
                                    {/if}
                                    <td>{$v.id}</td>
                                    <td>
                                            {php}
                                            $noHttp = strpos($v['head_100'], 'https://') === false;
                                            {/php}
                                        <a href="{php} if ($noHttp) {echo '__ROOT__';} {/php}{$v.head_100}" title="{$v.name}" target="_blank">
                                            <img style="width:40px;height:40px;" src="{php} if ($noHttp) {echo '__ROOT__';} {/php}{$v.head_100}"/>
                                        </a>
                                    </td>
                                    <td>{if condition='$v.delete_time'}<span style="color:red">{$v.name}</span>{else /}{$v.name}{/if}</td>
                                    <td>{$v.sex}</td>
                                    <td><a onclick="device('{$v.id}')" style="color:#40BCF7">{$v.device_account_count}</a></td>
                                    <!--<td>{$v.city}</td>-->
                                    <td>{$v.phone}</td>
                                    <td>{$v.volley}</td>
                                    <td>{$v.score}</td>
                                    <td><a onclick="topup('{$v.id}')" style="color:#40BCF7">{:round($v.topup_sum / 10, 2)}</a></td>
                                    <td><a onclick="consume('{$v.id}')" style="color:#40BCF7">{:round($v.consume_sum / 10)}</a></td>
                                    <td><a onclick="income('{$v.id}')" style="color:#40BCF7">{:round($v.income_sum / 10)}</a></td>
                                    {present name='reward'}
                                        {eq name='$reward' value='1'}
                                            <td>{$v.shouyi}</td>
                                            <td>{$v.shouyi_xuni}</td>
                                        {/eq}
                                    {/present}
                                    <td><a onclick="withdraw('{$v.id}')" style="color:#40BCF7">{:round($v.withdraw_sum / 10)}</a></td>
                                    <td>{$v.yqm}</td>
                                    <td><a onclick="team('{$v.yqm}')" style="color:#40BCF7">查看</a></td>
                                    <td>
                                        {if condition='$v.noble_grade && $v.noble_time >= time() && isset($vip[$v.noble_grade])'}
                                            <span onClick="huiyuan(this,{$v.id}, '{:date('Y-m-d H:i:s', $v.noble_time)}', {$v.noble_grade})" style="color:#40BCF7;cursor:pointer;">
                                                {$vip[$v['noble_grade']]['name']}
                                                <br>
                                                {:date('Y-m-d H:i:s', $v.noble_time)}
                                            </span>
                                        {else /}
                                            <span onClick="huiyuan(this,{$v.id}, '{:date('Y-m-d H:i:s')}', 0)" style="color:#40BCF7;cursor:pointer;">
                                            选择
                                            </span>
                                        {/if}
                                    </td>
                                    <!--<td>
                                        {eq name="$v.is_recommend" value="1"} 推荐中 {/eq}
                                    </td>-->
                                    <td>
                                        {switch name="v.is_identity_authentication"}
                                            {case value="0"}<a style="color:#40BCF7;cursor:pointer;" onClick="add('{:url('revideoadd',['id'=>$v['id'], 'url' => -1])}')">未认证</a>{/case}
                                            {case value="1"}<a style="color:red;cursor:pointer;" onClick="add('{:url('revideoadd',['id'=>$v['id'], 'url' => -1])}')">待审核</a>{/case}
                                            {case value="2"}<a style="color:green;cursor:pointer;" onClick="add('{:url('revideoadd',['id'=>$v['id'], 'url' => -1])}')">通过</a>{/case}
                                            {default /}未通过
                                        {/switch}
                                    </td>
                                    <td>{:date('Y-m-d H:i', strtotime($v.register_datetime))}</td>
                                    <!--<td>{$v.sort}</td>
                                    <td>
                                        {eq name='$v.is_contact' value='1'}
                                            <a onClick="add('{:url('Operate/contact',['user_id'=>$v['id'],'url'=>-1])}')" style="color:#40BCF7">已联系</a>
                                        {else /}
                                            <a onClick="add('{:url('Operate/contact',['user_id'=>$v['id'],'url'=>-1])}')" style="color:red">未联系</a>
                                        {/eq}
                                    </td>
                                    <td id="hide">{$hide[$v['is_banned']]}</td>-->
                                    <td>
                                        <div class="btn-group">
                                            <div data-toggle="dropdown" class="btn btn-primary btn-xs dropdown-toggle">
                                                操作 <span class="caret"></span>
                                            </div>
                                            <ul class="dropdown-menu">
                                                <li><a onClick="add('{:url('add',['id'=>$v['id'],'url'=>-1])}')">修改资料</a></li>
                                                <li class="divider"></li>
                                                <li><a onClick="add('{:url('personal',['id' => $v['id'], 'url' => -1])}')">个人配置</a></li>
                                                <li class="divider"></li>
                                                {eq name='admin.type' value='1'}
                                                    <!-- <li><a onClick="add('{:url('money',['id'=>$v['id'],'url'=>-1])}')">账户充值</a></li> -->
                                                    <li><a onClick="car(this, {$v.id})">赠送座驾</a></li>
                                                    <li class="divider"></li>
                                                {/eq}
                                                    <li><a onClick="frozen(this, {$v.id})">积分冻结</a></li>
                                                    <li><a onClick="topuplimit(this, {$v.id})">充值限额</a></li>
                                                    <li class="divider"></li>
                                                {eq name='admin.type' value='1'}
                                                    <li><a onClick="add('{:url('addvideo',['id'=>$v['id'],'url'=>-1])}')">上传视频</a></li>
                                                    <li><a onClick="add('{:url('addimage',['id'=>$v['id'],'url'=>-1])}')">上传照片</a></li>
                                                {/eq}
                                                <li><a onClick="add('{:url('image',['id'=>$v['id'],'url'=>-1])}')">查看照片</a></li>
                                                </li>
                                                <li class="divider"></li>
                                                <li><a onClick="add('{:url('CustomerService/topupPrev',['user_id'=>$v['id'],'url'=>-1])}')">上级充值</a></li>
                                                <li><a onClick="add('{:url('CustomerUserService/topupPrev',['user_id'=>$v['id'],'url'=>-1])}')">账户充值</a></li>
                                                <li class="divider"></li>
                                                <li><a onClick="delchats({$v.id})" style="color:red">清空聊天记录</a></li>
                                                <li class="divider"></li>
                                                <li><a onClick="del({$v.id})" style="color:red">注销账号</a></li>
                                            </ul>
                                        </div>
                                    </td>
                                </tr>
                                {/volist}
                                </tbody>
                            </table>
                        </form>
                    </div>
                </div>
            </div>
            <hr>
            <div class="row row-lg">
                <div class="col-sm-6">
                    <div  class="btn btn-outline btn-default" onclick="exportData(0)">
                        批量导出
                    </div>
                    <div  class="btn btn-outline btn-default" onclick="exportData(1)">
                        导出男性
                    </div>
                    <!--<a href="?reward=1" type="button" class="btn btn-outline btn-default">
                        收益排序
                    </a>-->
                    {eq name='admin.type' value='1'}
                    <div  class="btn btn-outline btn-default" onclick="alla('del')">
                        批量删除
                    </div>
                    {/eq}
                </div>
                <div class="col-sm-12 pages">{$page}</div>
            </div>
        </div>
    </div>
</div>
<div id="xuanze" style="text-align:center;display:none;margin: 0px 30px;padding:10px 100px">
    <div style="margin-bottom:10px"></div>
    <div style="display: flex;align-items: center;position: relative;">
        <span style="position: absolute;left: -80px;">VIP等级：</span>
        <select class="form-control" name="search_typeid">
            {volist name='vip' id='v'}
            <option name="huiyuan" value="{$v.id}" id="grade_{$v.grade}" class="grade" {eq name="key" value="0" }selected{/eq}>{$v.name}</option>
            {/volist}
            <option name="huiyuan" value="0" style="color: red">关闭资格</option>
        </select>
    </div>
    <div style="margin-bottom:10px"></div>
    <div style="display: flex;align-items: center;position: relative;">
        <span style="position: absolute;left: -80px;">到期时间：</span>
        <input type="text" id="time" class="form-control layui-input" value="" autocomplete="off">
    </div>
</div>

<div id="car" style="text-align:center;display:none;margin: 0px 30px;padding:10px 100px">
    <div style="margin-bottom:10px"></div>
    <select class="form-control" name="search_typeid">
        {volist name='car' id='v'}
        <option name="car" value="{$v.id}" {eq name="key" value="0" }selected{/eq}>{$v.name}</option>
        {/volist}
    </select>
    <div style="margin-bottom:10px"></div>
    <input type="text" id="cartime" class="form-control layui-input" value="" autocomplete="off" placeholder="赠送天数">
</div>
<div id="frozen" style="text-align:center;display:none;margin: 0px 30px;padding:10px 100px">
    <div style="margin-bottom:10px"></div>
    <input type="number" id="frozenvalue" class="form-control layui-input" value="" autocomplete="off" placeholder="冻结数量">
    <input type="text" id="frozenremark" class="form-control layui-input" value="" autocomplete="off" placeholder="冻结说明">
</div>
<div id="topuplimit" style="text-align:center;display:none;margin: 0px 30px;padding:10px 100px">
    <div style="margin-bottom:10px"></div>
    <input type="number" id="topuplimitvalue" class="form-control layui-input" value="" autocomplete="off" placeholder="每日限额；0表示不限制">
</div>
{include file="public/footer" /}
{load href="__PLUGINS__iCheck/icheck.min.js"}
{load href="__PLUGINS__iCheck/custom.css"}

<script type="text/javascript">

    $(document).ready(function(){
        $('#desAll').click(function(){
            var des=$(".form-horizontal").serialize();
            ajaxFun("post",'{:url("desAll")}',des,'json',function(ret){
                if(ret){
                    if(ret.ret){
                        self.location.reload();
                    }else{
                        layer.msg(ret.err)
                    }
                }else{
                    swal_msg("错误",ret,"error");
                }
            })
        })

        $('#delidAll').click(function(){
            $('input[type=checkbox]').each(function(){
                var self=$(this);
                if(!self.prop('checked')){
                    self.prop('checked',true);
                }else{
                    self.prop('checked',false);
                }
            });
        })

        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render ({
                elem : '#time', //指定元素
                type : 'datetime',
                trigger: 'click'
            });
        });
    });

    layui.use(['laydate'], function(){
        var laydate = layui.laydate;
        var form = layui.form;

        //执行一个laydate实例
        laydate.render({
            elem: '#date' //指定元素
            ,type: 'date'
            ,trigger: 'click'
        });
    })

    function del(id) {
        swal_del(id, "{:url('del')}")
    }
    function delchats(id) {
        swal_dels(id, "{:url('delchats')}")
    }
    

    function huiyuan(obj, id, time, grade) {

        $("#time").val(time);

        if (grade) {
            var grade_name = 'grade_' + grade;
            $("#" + grade_name).prop("selected", "selected");
        } else {
            $(".grade").removeAttr("selected");
        }

        var index = layer.open({
            area: ['540px', '240px'],
            type: 1,
            title: '选择VIP',
            content: $('#xuanze'),
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                var vip_id = $("option[name='huiyuan']:selected").val();
                var time = $("#time").val();
                $.ajax({
                    type: 'POST',
                    url: "{:url('admin/admin/addhuiyuan')}",
                    data: {vip_id: vip_id, user_id: id, time:time},
                    dataType: 'json',
                    success: function (date) {
                        if (date.state) {
                            layer.msg(date.msg, {icon: 1});
                            layer.close(index);
                            window.location.reload();
                        } else {
                            layer.msg(date.msg, {icon: 0});
                            layer.close(index);
                        }
                    },
                    error: function (e) {
                        layer.msg(e.responseText);
                    }
                });
            }
        })
    }

    function car(obj, id) {

        var index = layer.open({
            area: ['540px', '240px'],
            type: 1,
            title: '选择VIP',
            content: $('#car'),
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                var car_id = $("option[name='car']:selected").val();
                var time = $("#cartime").val();
                $.ajax({
                    type: 'POST',
                    url: "{:url('admin/admin/addcar')}",
                    data: {car_id: car_id, user_id: id, time:time},
                    dataType: 'json',
                    success: function (date) {
                        if (date.state) {
                            layer.msg(date.msg, {icon: 1});
                            layer.close(index);
                            window.location.reload();
                        } else {
                            layer.msg(date.msg, {icon: 0});
                            layer.close(index);
                        }
                    },
                    error: function (e) {
                        layer.msg(e.responseText);
                    }
                });
            }
        })
    }
    function frozen(obj, id) {

        var index = layer.open({
            area: ['540px', '200px'],
            type: 1,
            title: '积分冻结',
            content: $('#frozen'),
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                var value = $("#frozenvalue").val();
                var remark = $("#frozenremark").val();
                $.ajax({
                    type: 'POST',
                    url: "{:url('admin/admin/frozen')}",
                    data: {value: value,remark: remark, user_id: id},
                    dataType: 'json',
                    success: function (date) {
                        if (date.state) {
                            layer.msg(date.msg, {icon: 1});
                            layer.close(index);
                            window.location.reload();
                        } else {
                            layer.msg(date.msg, {icon: 0});
                            layer.close(index);
                        }
                    },
                    error: function (e) {
                        layer.msg(e.responseText);
                    }
                });
            }
        })
    }
    function topuplimit(obj, id) {

        var index = layer.open({
            area: ['540px', '200px'],
            type: 1,
            title: '充值限额',
            content: $('#topuplimit'),
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                var value = $("#topuplimitvalue").val();
                $.ajax({
                    type: 'POST',
                    url: "{:url('admin/member/topuplimit')}",
                    data: {value: value, user_id: id},
                    dataType: 'json',
                    success: function (date) {
                        if (date.state) {
                            layer.msg(date.msg, {icon: 1});
                            layer.close(index);
                            window.location.reload();
                        } else {
                            layer.msg(date.msg, {icon: 0});
                            layer.close(index);
                        }
                    },
                    error: function (e) {
                        layer.msg(e.responseText);
                    }
                });
            }
        })
    }



    function alla(types){
        var all=$(".form-horizontal").serialize();
        var alls=$(".form-horizontal").serializeArray();
        //console.log(JSON.stringify(alls))

        ajaxFun("post",'{:url("delAll")}?type='+types,all,'json',function(ret){

            if(ret){
                var text
                switch(types)
                {
                    case 0:
                        text='<font color="#f00">隐藏</font>';
                        break;
                    case 1:
                        text='<font color="#1ab394">通过</font>'
                        break;
                    case 2:
                        text ='审核';
                        break;
                    case 3:
                        text ='<font color="#f00">拒绝</font>';
                        break;
                }
                for(var i=0;i<alls.length;i++){
                    if(types=='del'){
                        $('#id'+alls[i]['value']).remove();
                    }else{
                        $('#hide'+alls[i]['value']).html(text);
                    }
                }

                swal_msg('操作成功')
                window.location.reload();
            }
        })

    }

    function team(id)
    {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("index")}?search=yqr&name='+id
            });
        });
    }

    function member(id)
    {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("index")}?search=yqm&name='+id
            });
        });
    }
    function device(deviceid)
    {
        if(!deviceid){
            return layer.msg('注销账号和空设备号不可查看')
        }
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("indexofip")}?search=uniaccount&name='+deviceid
            });
        });
    }

    function contact(id)
    {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("operate/contact")}?user_id='+id
            });
        });
    }

    function topup(id)
    {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("topup")}?state=1&search=id&name='+id
            });
        });
    }

    function consume(id)
    {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("balance")}?types=0&type=id&name='+id
            });
        });
    }

    function income(id)
    {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("shouyi/records")}?search=id&name='+id
            });
        });
    }

    function withdraw(id)
    {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("tixian")}?search=id&name='+id
            });
        });
    }

    function exportData(sex) {
        var all=$(".form-horizontal").serialize();

        if (!all && !sex) {
            layer.msg('未选中数据', {icon: 0});
        } else {
            window.location.href = '{:url("exportData")}?delAll='+all+'&sex='+sex;
        }
    }

    // 监听输入框
    function input(id){
        var val = $('#id'+id).find('.invite').val();

            /*if(!val){
                layer.msg('请输入邀请人ID');
                return;
            } else {*/
                layer.open({
                    content: '确认 绑定邀请人ID：' + val,
                    yes: function(index, layero){
                        //do something
                        layer.close(index); //如果设定了yes回调，需进行手工关闭

                        $.ajax({
                            type: 'post',
                            url: '{:url("inviteCode")}',
                            data: {id:id,prev_id:val},
                            dataType: 'json',
                            success:function(ret){
                                if (ret.ret) {
                                    layer.msg('设置成功')
                                    window.location.reload()
                                } else {
                                    layer.msg(ret.err);
                                }

                            },
                            error:function(err){
                                layer.msg(err)
                            }
                        });
                    }
                });
            /*}*/
    }
</script>
 